<!-- 首页 -->
<template>
	<view class="container">
		<TopNav title="积分统计" theme="white"></TopNav>

		<view class="main">
			<view class="flex justify-center">
				<Subsection :list="subsectionList" v-model="queryParams.type" @change="getData"></Subsection>
			</view>
			<view class="card m-t16">
				<view class="text-gray f-s12 text-center">
					<text>{{detailData.start}} - {{detailData.end}}</text>
				</view>
				<view class="flex justify-evenly align-center m-t12">
					<view class="text-center">
						<view class="">
							<text class="text-bold f-s28">{{detailData.total_integral || 0}}</text>
						</view>
						<view class="m-t11">
							<text class="text-gray f-s12">本期积分</text>
						</view>
					</view>

				</view>
				<view class="flex justify-between"
					style="background-color: #F5F6F7;border-radius: 12rpx;padding: 20rpx 24rpx;margin-top: 26rpx;">
					<view class="flex flex-direction align-center">
						<text class="text-bold f-s16">{{detailData.integral || 0}}</text>
						<text class="text-gray f-s12 m-t10">时长积分</text>
					</view>
					<view class="flex flex-direction align-center">
						<text class="text-bold f-s16">{{detailData.savings || 0}}</text>
						<text class="text-gray f-s12 m-t10">储值积分</text>
					</view>
					<view class="flex flex-direction align-center">
						<text class="text-bold f-s16">{{detailData.receive || 0}}</text>
						<text class="text-gray f-s12 m-t10">获赠积分</text>
					</view>
					<view class="flex flex-direction align-center">
						<text class="text-bold f-s16">{{detailData.duration || 0}}</text>
						<text class="text-gray f-s12 m-t10">在线时长</text>
					</view>
				</view>
			</view>
			<view class="m-t16">
				<view class="p-lr8">
					<text class="text-bold f-s15">积分明细</text>
				</view>
				<view class="tabs">
					<view class="tabs-item" v-for="(item,index) in tabsList" :key="index"
						:class="{'tabs-item-active':tabsCurrent === index}" @click="handleTabsChange(item,index)">
						<text>{{item.text}}</text>
					</view>
				</view>
			</view>
			<view class="flex-1 overflow-hidden m-t12">
				<scroll-view class="full-height" scroll-y="true" @scrolltolower="handleScrollBottom">
					<view class="radius bg-white list-item" v-for="(item,index) in list" :key="item.id">
						<view class="flex align-center justify-between">
							<text class="f-s15 text-bold">{{item.title}}</text>
							<text class="text-bold f-s16 col-text">+{{item.integral || 0}}</text>
						</view>
						<view class="m-t10">
							<text class="text-gray f-s12">{{item.date}}</text>
						</view>
					</view>
					<view class="padding-tb-xs" v-if="total !== 0">
						<u-loadmore :status="loadmoreStatus" line @loadmore="handleScrollBottom"/>
					</view>
					<Empty :show="total === 0" top="20rpx"></Empty>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import Subsection from '@/components/subsection/index.vue'
	import Empty from '@/components/empty/index.vue'
	import mixins from "@/mixins"
	import {integral,integralList} from '@/api/index/data.js'
	export default {
		name: "",
		mixins:[mixins],
		components: {
			Subsection,
			Empty
		},
		data() {
			return {
				detailData:{},
				list:[],
				tabsCurrent: 0,
				queryParams:{
					type:'',
					integral_type:'', // receive=获赠积分,integral=时长积分,savings=存储积分
					limit:10,
					page:1
				},
				tabsList: [{
					text: '时长积分',
					value:'integral'
				}, {
					text: '储值积分',
					value:'savings'
				}, {
					text: '获赠积分',
					value:'receive'
				}],
				subsectionList: [{
					label: '本期',
					value: 0
				}, {
					label: '上期',
					value: 1
				}]
			}
		},
		onLoad() {
			this.queryParams.type = this.subsectionList[0]['value']
			this.queryParams.integral_type = this.tabsList[0]['value']
			this.getData()
		},
		methods: {
			handleTabsChange(select,index){
				this.tabsCurrent = index
				this.queryParams.page = 1
				this.queryParams.integral_type = select['value']
				this.getList()
			},
			getData(){
				this.getDetail()
				this.getList()
			},
			getDetail(){
				integral({type:this.queryParams.type}).then(res=>{
					let {data} = res
					this.detailData = data
				})
			},
			getList(){
				integralList(this.queryParams).then(res=>{
					let {data:{list,count,total}} = res
					this.total = count || 0
					this.pageTotal = total || 0
					if(this.queryParams.page === this.pageTotal) this.loadmoreStatus = 'nomore'
					if(this.queryParams.page === 1){
						this.list = list
					}else if(this.queryParams.page < this.pageTotal){
						this.list = this.list.concat(list)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import '@/common/css/var.scss';

	.container {
		background: url('/static/images/index/statictics-bg.png') no-repeat fixed top center / 100% auto;

		.main {
			padding: 24rpx;
			padding-top: 36rpx;
			@include fixed-height;
			overflow: hidden;
			display: flex;
			flex-direction: column;

			.card {
				width: 100%;
				border-radius: 20rpx;
				background-color: #fff;
				padding: 20rpx 16rpx 16rpx 16rpx;
				margin-bottom: 20rpx;

				.card-line {
					width: 2rpx;
					height: 72rpx;
					background-color: #DDE0E6;
				}
			}

			.tabs {
				display: flex;
				margin: 24rpx 0 20rpx 0;

				.tabs-item {
					border-radius: 32rpx;
					padding: 16rpx 32rpx;
					font-weight: 400;
					font-size: 24rpx;
					background-color: #fff;
					margin-right: 20rpx;
				}

				.tabs-item-active {
					background-color: #121924;
					color: #fff;
				}
			}

			.list-item {
				padding: 24rpx;
				margin-bottom: 20rpx;
			}
		}
	}
	
</style>